// pages/my/my.js
const app = getApp()
var WxNotificationCenter = require("../../config/WxNotificationCenter");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    funList: [{
        icon: '../../static/images/me/me_list_1.png',
        name: '会议室管理',
        router: '/pages/conferenceManage/list/conferenceMList'
      },
      {
        icon: '../../static/images/me/me_list_2.png',
        name: '商品管理',
        router: '/pages/goodsManagement/list/goodsManagement'
      },
      {
        icon: '../../static/images/me/me_list_3.png',
        name: '车辆管理',
        router: '/pages/vehiclemanagement/carmanage/carmanage'
      },
      {
        icon: '../../static/images/me/me_list_3.png',
        name: '车辆预约审核',
        router: '/pages/vehiclemanagement/vehiclemanagement'
      },
      {
        icon: '../../static/images/me/me_list_4.png',
        name: '司机管理',
        router: '/pages/drivermanagement/drivermanagement'
      },
      {
        icon: '../../static/images/me/me_list_5.png',
        name: '用户管理',
        router: '/pages/usermanage/usermanage'
      },
      {
        icon: '../../static/images/me/me_list_6.png',
        name: '订单核批',
        router: '/pages/order/orderExamine/orderExamine'
      },
      {
        icon: '../../static/images/me/me_list_6.png',
        name: '领导邮箱',
        router: '/pages/forumManage/forumManage'
      },
      {
        icon: '../../static/images/me/me_list_7.png',
        name: '任务管理',
        router: '/pages/management/management'
      },
    ]
  },
  logout() {
    console.log('退出')
    wx.navigateTo({
      url: '../loginpage/loginpage',
    })
  },
  goroute(e) {
    //判断登录
    if (this.gotologin()) {
      return;
    }

    let route = e.currentTarget.dataset.route;
    let name = e.currentTarget.dataset.name;
    if (!route) {
      wx.showToast({
        title: '维护中...',
        icon: 'none'
      })
    } else {
      // 检测权限
      if (app.checkFun(name)) {
        wx.navigateTo({
          url: route,
        })
      }

    }
  },
  gotologin() {
    if (app.globalData.islogin) {
      return false;
    }
    wx.navigateTo({
      url: '../loginpage/loginpage',
    })
    return true;
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    let that = this;
    WxNotificationCenter.addNotification("loginsuccess", that.getuserinfo, that);
    this.getuserinfo();
  },
  getuserinfo() {

    let userInfo = app.globalData.userInfo;
    if (userInfo) {
      this.setData({
        userInfo: userInfo
      })
    }
    console.log('userInfo:', this.data.userInfo)

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})